package com.lovo.student.frame;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

import com.lovo.common.model.SysDictBean;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoComboBox;
import com.lovo.netCRM.component.LovoCutPage;
import com.lovo.netCRM.component.LovoList;
import com.lovo.netCRM.component.LovoTable;
import com.lovo.netCRM.component.LovoTitleLabel;
import com.lovo.netCRM.component.LovoTitlePanel;
import com.lovo.netCRM.component.LovoTxt;


/**
 * 学生管理主面板
 * @author 白德柯
 *
 */
public class StudentPanel extends JPanel{

	/**学生表格组件*/
	private LovoTable studentTable;
	/**窗体组件*/
	private JFrame jf;
	/**学生姓名文本框*/
	private LovoTxt nameTxt;
	/**班级文本框*/
	private LovoTxt classTxt;
	/**状态下拉框*/
	private LovoComboBox<SysDictBean> statusComboBox;
	/**学校列表*/
	private LovoList schoolList;
	/**分页对象*/
	private LovoCutPage cutPage;
	public StudentPanel(JFrame jf){
		this.jf = jf;
		this.setLayout(null);
		this.init();
	}
	/**
	 * 初始化
	 *
	 */
	private void init() {
		new LovoTitleLabel("学 生 管 理",this);
		this.initTable();
		this.initList();
		this.initButton();
		this.initFindPanel();
		this.initData();
	}
	/**
	 * 初始化数据
	 */
	public void initData(){
		this.updateTable(1);
	}
	/**
	 * 初始化按钮
	 *
	 */
	private void initButton() {
		LovoButton addButton = new LovoButton(50,460,"添加学生","image/add.png",this);
		
		addButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new StudentAddDialog(jf, 0,StudentPanel.this);
			}
		});
		
		LovoButton updateButton = new LovoButton(250,460,"修改学生","image/update.png",this);
		
		updateButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new StudentUpdateDialog(jf, 0,StudentPanel.this);
			}
		});
		
		LovoButton delButton = new LovoButton(50,525,"删除学生","image/del.png",this);

		LovoButton showButton = new LovoButton(250,525,"查看学生信息","image/find.png",this);
		
		showButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new StudentShowDialog(jf, 0);
			}
		});
		

	}
	/**
	 * 初始化查询按钮
	 *
	 */
	private void initFindPanel(){

		LovoTitlePanel jp = new LovoTitlePanel("查询学生信息",400, 460, 320, 160,this);
		this.nameTxt = new LovoTxt("姓名",30,30,jp);
		this.classTxt = new LovoTxt("班级",30,60,jp);
		this.statusComboBox = new LovoComboBox("状态",new ArrayList(),30,90,jp);
		
		LovoButton findButton = new LovoButton("查找",180,120,jp);
		findButton.setSize(60, 20);

		
	}

	
	//-------------------------------------------------
	/**
	 * 初始化表格
	 *
	 */
	private void initTable() {
		studentTable = new LovoTable(this,
				new String[]{"学生姓名","性别","班级","状态","联系电话"},
				new String[]{},//学生实体属性名数组 new String[]{"name","sex"}
				"");//主键属性名
		studentTable.setSizeAndLocation(220, 90, 500, 300);
		// 分页
		cutPage = new LovoCutPage(220,400,this) {
			@Override
			public void clickEvent(int arg0) {
				
			}
		};
		
	}
	/**
	 * 初始化列表
	 */
	private void initList() {
		schoolList = new LovoList(20, 90, 195, 300, new ArrayList(), this);
		schoolList.setBorder(BorderFactory.createEtchedBorder());
	}
	/**
	 * 更新表格数据
	 */
	private void updateTable(int page){
		//更新表格
		studentTable.updateLovoTable(null);
	}
	

}
